package com.atues.kuangshengjuc.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableTest {
    //new Thread(new Runnable()).start
    //new Thread(new FutureTask<V>()).start
    //new Thread(new FutureTask<V>(Callable)).start

    public static void main(String[] args) {
        FutureTask futureTask = new FutureTask(new MyThread());
        new Thread(futureTask,"A").start();
        new Thread(futureTask,"B").start();//有缓存，只会输出一个callable
        try {
            System.out.println(futureTask.get());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }

}

class   MyThread implements Callable{
    @Override
    public Object call() throws Exception {
        System.out.println("callable");
        return "1111";
    }
}
